﻿package com.ostrich.project.service.impl;

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.service.BaseService;
import com.ostrich.manpower.common.FormulaUtil;
import com.ostrich.project.bean.TostPjPushmoney;
import com.ostrich.project.service.TostPjPushmoneyDao;

/**
 * @author wangyinan
 * @brief 模块功能简单描述
 * @details 模块功能详细描述
 */
@Service("tostPjPushmoneyService")
public class TostPjPushmoneyService<T> extends BaseService<T> {
	private final static Logger log = Logger
			.getLogger(TostPjPushmoneyService.class);

	@Autowired
	private TostPjPushmoneyDao<T> dao;

	public TostPjPushmoneyDao<T> getDao() {
		return dao;
	}

	public void pjpusqw(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		TostPjPushmoney pjpus = new TostPjPushmoney();
		if (pjpus != null) {
			Map<String, Object> fMap = FormulaUtil.formulaById(2,
					pjpus.getPpuBasepercent(), pjpus.getPpuAwardpercent(),
					pjpus.getPpuCount());
			if (fMap != null) {
				pjpus.setPpuArea((Float) fMap.get("one")); // 基础提成
				pjpus.setPpuPrice((Float) fMap.get("two"));// 奖金提成
				Map<String, Object> ensub = FormulaUtil.formulaById(1,
						pjpus.getPpuArea(), pjpus.getPpuPrice());// 金额
				pjpus.setPpuCount((Float) ensub.get("csum"));
				dao.add((T) pjpus);
			}
		}
	}

	// 查询所属部门
	public java.util.List<TostPjPushmoney> queryPush() {
		java.util.List<TostPjPushmoney> list = new ArrayList<TostPjPushmoney>();
		list = dao.queryselectById();
		return list;
	}

	/***
	 * 添加部门信息
	 * 
	 * @param t
	 * @throws Exception
	 */
	public void addDept(TostPjPushmoney t) throws Exception {
		TostPjPushmoney td = (TostPjPushmoney) t;
		dao.addDept(td);
	}

	// 获取父节点的最大id值
	public String getMaxByHdpPid(String hdpPid) {
		return dao.queryMaxIdByPid(hdpPid);
	}

	// 根据名字去id
	public String queryidByname(String str) {
		return dao.queryidByname(str);
	}
	
	public void deleteByPctId(Integer pctId) throws Exception{
		 dao.deleteByPctId(pctId);
	}
}
